<?php
$pubs = Publication::get_publications();
?>


    <table class="subscription-table">
    <thead>
        <tr class="heading-row skin-gradient">
        <td>#</td>
        <th>ID</th>
        <th>Name</th>
        <th>Email</th>
        <th>Controls</th>
        </tr>       
    </thead>
    
    <tbody>
    
    <?php
    $i = 0;
    foreach( $pubs as $pub ) {
    $i ++;
    ?>
        <tr>
            <td><?php echo $i; ?></td>
            <td><?php echo $pub->publication_id; ?></td>
            <td><?php echo $pub->name; ?></td>
            <td><a href="mailto:<?php echo $pub->setting_email; ?>"><?php echo $pub->setting_email; ?></a></td>
            <td class="controls group">
                <a class="show-tool-tip" href="<?php echo $Controller->page_url('home'); ?>&delete=publication&id=<?php echo $pub->publication_id; ?>" title="Deleting a publication is <em>PERMANENT</em> and highly discouraged."> Delete </a>
            </td>
        </tr>
    <?php
    }
    ?>
    </tbody>
            
     <table class="subscription-table margin-top">
         <thead>
            <tr class="heading-row skin-gradient">
                <th class=""><h1 class="section-title">Add new publication</h1></th>
            </tr>
        </thead>
        
        <tbody>

            <tr>
                <td class="align-top text-left">
                    <form class="edit-form" method="post" action="">
                        
                    <label><span>Name:</span>
                    <input type="text" value="" name="name" />
                    </label>
                    
                    <label><span>Added:</span>
                    <input type="text" readonly value="<?php echo date("F j Y"); ?>" name="datestamp" />
                    </label>

                    
                    <label><span>Publication Day:</span>
                        <select name="publication_day">
                            <?php for ( $i = 1; $i <= 7; $i ++ ) { ?>
                                  <option value="<?php echo $i; ?>"><?php echo $weeks[$i-1]; ?></option>
                            <?php } ?>
                        </select>
                    <span class="show-tool-tip" title="The day your publication is officially mailed out. The day after is the day your subscription management system rolls over into the next week.">?</span>
                    </label>
                    
                    <label><span>Records Per Page:</span>
                    <input type="number"  value="100" name="setting_records_per_page" />
                    <span class="show-tool-tip" title="Controls how many subscriptions are displayed in the main subscription area. Increasing this amount may increase loading times, please find a suitable balance.">?</span>
                    </label>
                    
                    <label><span>Notify Me of Expiring Subscriptions X Weeks Before:</span>
                    <input type="number"  value="4" name="setting_expiring_tolerance" />
                    <span class="show-tool-tip" title="Subscriptions will be flagged as Expiring this many weeks prior to their expiration. In addition, EXPIRED subscriptions will remain on Expiration Reports for this many weeks before falling off.">?</span>
                    </label>
                    
                    <label><span>Subscription Grace Period:</span>
                        <input type="number"  value="2" name="setting_expired_tolerance" />
                        <span class="show-tool-tip" title="Expired subscriptions will receive thier issues for X weeks after expiration.">?</span>
                    </label>
                            
                    </label>
                    <label><span>Local Towns:</span>
                    <textarea name="setting_local_locations"></textarea>
                    <span class="show-tool-tip" title="Please list local towns of interest in a Comma Separated List. <em>Eg: town, town, town</em>">?</span>
                    </label>
                    
                    
                    <label><span>Province:</span>
                        <select name="setting_province">
                        <?
                        foreach ( $provinces as $key => $value ) {
                                echo '<option value="'.$key.'">'.$value.'</option>';
                        } ?>
                        </select>
                    <span class="show-tool-tip" title="The Province of origin for your publication. This setting will affect all your local/regional totals.">?</span>
                    </label>
                    
                    <label><span>Country:</span>
                        <select name="setting_country">
                            <option value="Canada" default>Canada</option>
                        </select>
                    <span class="show-tool-tip" title="The country of origin for your Publication. This setting will affect your national/foreign totals.">?</span>
                    </label>
                    
                    <hr>
                    <label><span>Email:</span>
                    <input type="email"  value="" name="setting_email" />
                    <span class="show-tool-tip" title="The email supplied here will be your admin email. Notifications and Reports will be auto-sent here. Please make sure it's valid and used actively.">?</span>
                    </label>
                    
                    <label><span>Username:</span>
                    <input type="text"  value="" name="username" />
                    </label>
                    
                    <label><span>New Password:</span>
                    <input type="password"  value="" name="password1" placeholder="&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;"/>
                    <span class="show-tool-tip" title="Passwords must match. Passwords are case sensitive.">?</span>
                    </label>
                    
                    <label><span>Confirm Password:</span>
                    <input type="password"  value="" name="password2" placeholder="&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;"/>
                    </label>
                    
                    <label><span>Table Name:</span>
                    <input type="text"  value="" name="table_name" placeholder="xxxx"/>
                    </label>
                    
                    <input hidden type="hidden"  value="" name="rollover_date" />
                    <input hidden type="hidden"  name="action" value="update_publication" />

                        <div class="right group">
                            <input class="right primary-button skin-gradient" type="submit" name="update_publication" value="Save" />
                        </div>       
                </form>
                </td>
            </tr>
        </tbody>
    </table>
    <br>
    <a class="button-text" href="?action=logout"> Logout </a>
